package com.ssy.lingxi.contract.job;

import com.ssy.lingxi.contract.service.IContractManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务配置
 * @author yzc
 * @version 2.0.0
 * @date 2021/2/23
 */
@Slf4j
@EnableScheduling
@Component
public class SignScheduler {

    @Resource
    private SignFlowCheckJobService signFlowCheckJobService;
    @Resource
    private SignAuthCheckJobService signAuthCheckJobService;
    @Resource
    private IContractManageService contractManageService;

    @Scheduled(cron = "0 0/20 * * * ?")
    public void signFlowTask() {
        try {
            signFlowCheckJobService.checkSignFlow();
        } catch (Exception e) {
            log.error("执行签署流程查询任务失败", e);
        }
    }

    @Scheduled(cron = "0 0/20 * * * ?")
    public void signAuthTask() {
        try {
            signAuthCheckJobService.checkSignAuth();
        } catch (Exception e) {
            log.error("执行认证流程查询任务失败", e);
        }
    }

    @Scheduled(cron = "0 10 * * * ?")
    public void updateExpiredContract() {
        try {
            contractManageService.updateExpiredContract();
        } catch (Exception e) {
            log.error("[定时任务][合同]执行过期合同状态更新失败", e);
        }
    }
}
